import { ADD, SUB } from '../../actionTypes'

// 1. 初始化状态数据
const initState = {
	num: 99,
}
// 2. 导出一个函数
export default (state = initState, { type, payload }) => {
	// 3. 对state 进行深拷贝
	let newState = JSON.parse(JSON.stringify(state))
	switch (type) {
		case ADD:
			newState.num += payload.num
			break
		case SUB:
			newState.num += payload.num
			break
	}
	return newState
}
